<template>
    <div>
        <!-- 企业产值 -->
         <!-- :dialog-style="{ top: '20px' }" -->
        <a-modal
         v-model:visible="visible" 
         :title="formState.id?(formState.view?'查看':'编辑'):'新增'" 
         @ok="handleOk" 
         @cancel="visible = false"
         class="enterprise-addEdit5-modal-5"
         width="80%"
         :footer="null"
        >
            <div v-if="visible">
                <a-form :form="form" layout="horizontal" class="form-descriptions-content-box">
                    <a-descriptions :column="4" bordered >
                        <a-descriptions-item >
                            <span slot="label" class="descriptions-label-slot">
                                <span class="xhText">*</span>
                                年份
                            </span>
                            <a-form-item class="zm-form-model">
                                <span v-if="formState.view">{{ moment(formState.fnf).format('YYYY') }}</span>
                                <a-date-picker
                                    v-else
                                    v-model:value="formState.fnf"
                                    v-decorator="[
                                        'fnf', { initialValue:formState.fnf, rules: rules.fnf}
                                    ]"
                                    mode="year"
                                    format="YYYY"
                                    placeholder="请选择年份"
                                    @panelChange="panelChange"
                                    style="width: 100%;"
                                    :key="yearPickerKey"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item >
                            <span slot="label" class="descriptions-label-slot">
                                <span class="xhText">*</span>
                                总产值（万元）
                            </span>
                            <a-form-item class="zm-form-model">
                                <span v-if="formState.view">{{ formState.fzcz }}</span>
                                <a-input
                                    v-else
                                    v-model:value="formState.fzcz" 
                                    placeholder="请输入总产值（万元）"
                                    v-decorator="[
                                        'fzcz', { initialValue:formState.fzcz, rules: rules.fzcz}
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item >
                            <span slot="label" class="descriptions-label-slot">
                                <span class="xhText">*</span>
                                营业税金（万元）
                            </span>
                            <a-form-item class="zm-form-model">
                                <span v-if="formState.view">{{ formState.fyysj }}</span>
                                <a-input
                                    v-else
                                    v-model:value="formState.fyysj" 
                                    placeholder="请输入营业税金（万元）"
                                    v-decorator="[
                                        'fyysj', { initialValue:formState.fyysj, rules: rules.fyysj}
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item >
                            <span slot="label" class="descriptions-label-slot">
                                <span class="xhText">*</span>
                                年度新增产品产值（万元）
                            </span>
                            <a-form-item class="zm-form-model">
                                <span v-if="formState.view">{{ formState.fndxzcpcz }}</span>
                                <a-input
                                    v-else
                                    v-model:value="formState.fndxzcpcz" 
                                    placeholder="请输入年度新增产品产值（万元）"
                                    v-decorator="[
                                        'fndxzcpcz', { initialValue:formState.fndxzcpcz, rules: rules.fndxzcpcz}
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                    </a-descriptions>
                </a-form>
            </div>
            <div style="
                display: flex; justify-content: flex-end;
                margin-top: 20px; width: 100%;
                background-color: #fff;">
                <a-button @click="visible = false">取消</a-button>
                <a-button v-if="!formState.view" style="margin: 0 20px;" class="blue-btn" type="primary" @click="handleOk(true)">保存</a-button>
                <a-button v-if="!formState.view" class="blue-btn" type="primary" @click="handleOk(false)">保存并关闭</a-button>
            </div>
        </a-modal>
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector.vue'
import moment from 'moment'
export default {
    components:{
        compSelector,
    },
    props:{

    },
    data(){
        return{
            visible:false,
            formState:{},
            moment,
            form: this.$form.createForm(this, { name: 'coordinated' }),
            rules:{
                fnf: [{
                    required: true,
                    type:'object',
                    message: '请选择年份',
                    trigger: 'blur',
                }],
                fzcz: [{
                    required: true,
                    message: '请输入总产值（万元）',
                    trigger: 'blur',
                }],
                fyysj: [{
                    required: true,
                    message: '请输入营业税金（万元）',
                    trigger: 'blur',
                }],
                fndxzcpcz: [{
                    required: true,
                    message: '请输入年度新增产品产值（万元）',
                    trigger: 'blur',
                }],
            },
            yearPickerKey:null,
        }
    },
    watch:{

    },
    mounted(){
    },
    methods:{
        getData(val){
            this.formState = {}
            this.formState = {...val,fnf:val.fnf?moment(val.fnf):''}
        },
        panelChange(val){
            this.formState.fnf = val
            this.form.setFieldsValue({
                fnf:val
            });
            this.yearPickerKey = Date.now()
        },
        handleOk(val){
            this.form.validateFields((err, values) => {
                if (!err) {
                    if(this.formState.id){
                        this.$emit('editItem',{
                            ...this.formState,
                            ...values,
                            fnf:moment(this.formState.fnf).format('YYYY'),
                        },val)
                    }else{
                        this.$emit('addItem',{
                            ...this.formState,
                            ...values,
                            fnf:moment(this.formState.fnf).format('YYYY'),//YYYY-MM-DD
                        },val)
                    }
                    
                }
            })
        },
    }
}
</script>
<style lang="less">
.enterprise-addEdit5-modal-5{
    .add-edit-form{
        display: flex;
        flex-wrap: wrap;
        .ant-form-item{
            display: flex;
            margin-bottom: 8px;
        }
        .ant-form-item-label{
            width: 110px;
        }
        .ant-form-item-control-wrapper{
            width: 100%;
        }
        .flex-1-box{
            width: 100%;
            .ant-form-item-control-wrapper{
                flex: 1;
            }
        }
        .flex-05-box{
            width: 50%;
            .ant-form-item-control-wrapper{
                flex: 1;
            }
        }
    }
}
</style>